home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue66 / Construc / ClientForm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-01-03  |  1.6 KB  |  73 lines

  1. unit ClientForm;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   Corba, DrBob42_i, DrBob42_c, StdCtrls;
  6.  
  7. type
  8.   TForm1 = class(TForm)
  9.     ButtonDeposit: TButton;
  10.     LabelBalance: TLabel;
  11.     ButtonWithdraw: TButton;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure ButtonDepositClick(Sender: TObject);
  14.     procedure ButtonWithdrawClick(Sender: TObject);
  15.   private
  16.   { private declarations }
  17.     Rate: Rates;
  18.     Acct: Account;
  19.     MyAcct: MyAccount;
  20.   protected
  21.   { protected declarations }
  22.     procedure InitCorba;
  23.   public
  24.   { public declarations }
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31. {$R *.DFM}
  32.  
  33. procedure TForm1.InitCorba;
  34. begin
  35.   CorbaInitialize;
  36.   Rate := TRatesHelper.Bind;
  37.   Acct := TAccountHelper.Bind;
  38.   MyAcct := TMyAccountHelper.Bind;
  39. end;
  40.  
  41. procedure TForm1.FormCreate(Sender: TObject);
  42. begin
  43.   InitCorba;
  44. end;
  45.  
  46. procedure TForm1.ButtonDepositClick(Sender: TObject);
  47. begin
  48.   Assert(MyAcct <> nil,'No connection to CORBA Server');
  49.   MyAcct.deposit(1);
  50.   LabelBalance.Caption :=
  51.       Format('Current balance: %f (%f%%)',
  52.         [MyAcct.balance,MyAcct.get_rates(Rate)])
  53. end;
  54.  
  55. procedure TForm1.ButtonWithdrawClick(Sender: TObject);
  56. begin
  57.   Assert(MyAcct <> nil,'No connection to CORBA Server');
  58.   try
  59.     try
  60.       MyAcct.withdraw(42);
  61.     except
  62.       on E: EAccountException do
  63.         ShowMessage(Format(E.Error.ErrorMessage,[E.Error.Balance]))
  64.     end
  65.   finally
  66.     LabelBalance.Caption :=
  67.       Format('Current balance: %f (%f%%)',
  68.         [MyAcct.balance,MyAcct.get_rates(Rate)])
  69.   end;
  70. end;
  71.  
  72. end.
  73.